package com.cosmoplat.xikai.business.modbus.slave;


import com.cosmoplat.xikai.business.modbus.utils.Modbus4jUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author zhangyanda
 */
@Component
@Slf4j
public class Slave {
    @Value("${modbus.port}")
    private String port;
    @Value("${modbus.slaveId}")
    private String slaveId;

    @Bean
    public void createSlave() throws Exception {
        run();
    }

    public void run() throws Exception {
        new Thread(() -> {
            Modbus4jUtils.createSalve(Integer.parseInt(port), Integer.parseInt(slaveId));
        }).start();
    }


}